package cn.damong.response;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * 返回给前端页面的分页数据对象
 * 
 * @author CodingPanda
 * @2019年5月15日 下午10:26:48
 *
 * @param <T>
 */
public class ApiListResponse<T> implements Serializable{
    private static final long serialVersionUID = 8094351795560752508L;

    /**
	 * 错误代码，成功时设置为1，失败时按照规范生成相应的错误代码
	 */
	private String code;
	
	/**
	 * 当code不为1时，错误提示信息
	 */
	private String message;
	
	/**
	 * API需要返回的额外信息
	 */
	private List<T> data;
	
	/**
	 * 可能需要返回的其他数据信息
	 */
	private Map<Object, Object> mapData;
	
	/**
	 * 分页信息
	 */
	private Page page;
	
	public ApiListResponse(){
		
	}
	
	public ApiListResponse(ErrorCode code){
		this.code = code.getValue();
		this.message = code.getMessage();
	}
	
	public ApiListResponse(ErrorCode code, String message){
        this.code = code.getValue();
        this.message = message;
    }
	
	public ApiListResponse(ErrorCode code, List<T> data){
		this.code = code.getValue();
		this.message = code.getMessage();
		this.data = data;
	}
	
	public ApiListResponse(ErrorCode code, List<T> data, Page page){
		this.code = code.getValue();
		this.message = code.getMessage();
		this.data = data;
		this.page = page;
	}
	
	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public List<T> getData() {
		return data;
	}

	public void setData(List<T> data) {
		this.data = data;
	}

	public Page getPage() {
		return page;
	}

	public void setPage(Page page) {
		this.page = page;
	}

	public Map<Object, Object> getMapData() {
		return mapData;
	}

	public void setMapData(Map<Object, Object> mapData) {
		this.mapData = mapData;
	}

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((code == null) ? 0 : code.hashCode());
        result = prime * result + ((data == null) ? 0 : data.hashCode());
        result = prime * result + ((mapData == null) ? 0 : mapData.hashCode());
        result = prime * result + ((message == null) ? 0 : message.hashCode());
        result = prime * result + ((page == null) ? 0 : page.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        ApiListResponse other = (ApiListResponse) obj;
        if (code == null) {
            if (other.code != null) {
                return false;
            }
        } else if (!code.equals(other.code)) {
            return false;
        }
        if (data == null) {
            if (other.data != null) {
                return false;
            }
        } else if (!data.equals(other.data)) {
            return false;
        }
        if (mapData == null) {
            if (other.mapData != null) {
                return false;
            }
        } else if (!mapData.equals(other.mapData)) {
            return false;
        }
        if (message == null) {
            if (other.message != null) {
                return false;
            }
        } else if (!message.equals(other.message)) {
            return false;
        }
        if (page == null) {
            if (other.page != null) {
                return false;
            }
        } else if (!page.equals(other.page)) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "ApiListResponse [code=" + code + ", message=" + message + ", data=" + data + ", mapData=" + mapData
                + ", page=" + page + "]";
    }

}
